<jsp:include page="header.jsp" />
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ include file="loginDetails.jsp" %>
<%
	Integer access = null;
	String username = (String)session.getAttribute("authenticatedUser");
	access = (Integer)session.getAttribute("access");
	if(access == null)
	{
		response.sendRedirect("login.jsp");
	}
%>
<form class="navbar-search pull-right" method ="POST" action ="search_by_name.jsp">
  <input type="text" id ="search" name="search"class="search-query" placeholder="Search By Name">
  <button type="submit" class="btn btn-primary">Search</button>
</form>

<%
String partialName = request.getParameter("search");
if(partialName == null)
{
	
}
else
{
	ResultSet rst = null;
	Connection con = null;
	try{

		con = DriverManager.getConnection(url, user_id, pass); 
		Statement stmt = con.createStatement();
		rst = stmt.executeQuery("SELECT * FROM people WHERE name LIKE '%" + partialName + "%' OR name = '" + partialName + "';");
		
	}catch(Exception e){
		
	}
	out.print("<table class=\"table table-striped table-bordered\" style=\"margin-top:50px;\"><thead><tr><th>Name</th><th>Gender</th><th>Date Of Birth</th><th>Date Of Death</th></tr></thead>");
	while(rst.next()){
		
	

%>
        <tr>
            <td><%=rst.getString("name") %></td>
            <td><%=rst.getString("gender") %></td>
            <td><%=rst.getDate("date_of_birth") %></td>
            <td><%=rst.getDate("date_of_death") %></td>
            <td>
             <div class="btn-group">
                    <a href="more_info.jsp?id=<%=rst.getString("id") %>" class="btn btn-primary">More Information</a>
                   
                </div>
            </td>
        </tr>
<%
	}
}
%>
</table>

<jsp:include page="footer.jsp" />